﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using web.data.entities;
using web.bussines;
using Webdiyer.WebControls.Mvc;
using System.Web.UI;
using web.core.Controllers;

namespace web.core.Models
{
    public class weblinkModels
    {

        //get all get all
        public static PagedList<web_link> get_plist(int pageindex, int pagesize, int language_id, string link_type)
        {
            var obj = new web_link_service();
            return obj.get_plist(pageindex, pagesize, language_id, link_type);
        }

        public static List<web_link> list_by_type(int language_id, string link_type)
        {
            var obj = new web_link_service();
            return obj.list_by_type(language_id, link_type);
        }

        public static int weblink_update(web_link it)
        {
            var obj = new web_link_service();
            return obj.weblink_update(it);
        }

        //get items by id or code
        public static web_link getByID(int id)
        {
            var obj = new web_link_service();
            return obj.getByID(id);
        }

        //delete by id
        public static void deleteItem(int id)
        {
            var obj = new web_link_service();
            //delete all images
            var item = getByID(id);
            if (item != null)
            {
                if (!string.IsNullOrEmpty(item.image_path))
                    baseController.DeleteFile(item.image_path);
            }
            //delete record in db
            obj.deleteItem(id);
        }
    }
}